//jquery.json
(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);


/**
 * 成功弹出框
 * 
 * @param {}
 *            content 内容
 */
function jrSuccess(content) {
	window.parent.jQuery.ligerDialog.success(content);
}

/**
 * 提示弹出框
 * 
 * @param {}
 *            content 内容
 */
function jrWarn(content) {
	window.parent.jQuery.ligerDialog.warn(content);
}

/**
 * Alert提示框
 * 
 * @param {}
 *            content 内容
 */
function jrAlert(content) {
	window.parent.jQuery.ligerDialog.alert(content, "提示");
}

/**
 * 错误弹出框
 * 
 * @param {}
 *            content 内容
 */
function jrError(content) {
	window.parent.jQuery.ligerDialog.error(content);
}

/**
 * 问题弹出框
 * 
 * @param {}
 *            content 内容
 */
function jrQuestion(content) {
	window.parent.jQuery.ligerDialog.question(content);
}

/**
 * 确认弹出框
 * 
 * @param {}
 *            content 内容
 * @param {}
 *            fun 回调函数
 */
function jrConfirm(content, fun) {
	window.parent.jQuery.ligerDialog.confirm(content, function(yes) {
				fun(yes);
			});
}

/**
 * 警告弹出框
 * 
 * @param {}
 *            content 内容
 * @param {}
 *            fun 回调函数
 */
function jrWarning(content, fun) {
	window.parent.jQuery.ligerDialog.warning(content, function(yes) {
				fun(yes);
			});
}

/**
 * 根据索引删除行
 * 
 * @param {}
 *            index 索引
 */
function jrDeleteRow(index) {
	grid.deleteRow(grid.getRowObj(index));
}

/**
 * 为grid增加便行
 * 
 * @param {}
 *            obj 行对象
 */
function jrAddEditRow(obj) {
	grid.addEditRow();
}

window.parent.jQuery.ligerui.controls.Dialog.prototype._borderX = 2;
window.parent.jQuery.ligerui.controls.Dialog.prototype._borderY = 0;

/**
 * Window弹出
 * 
 * @param {}
 *            url iframe路径
 * @param {}
 *            title 标题
 * @param {}
 *            width 宽度
 * @param {}
 *            height 高度
 */
function jrWindow(url, title, width, height, haveDel) {
	var btns = [];
	btns.push({
		text : '确定',
		onclick : function(item, dialog) {
			var rs = dialog.frame.doSub(dialog);
			var ifid;
			if (typeof(parent.tab) != 'undefined') {
				ifid = parent.tab.getSelectedTabItemID();
				if (typeof(parent.document.getElementById(ifid).contentWindow.grid) != 'undefined') {
					parent.document.getElementById(ifid).contentWindow.grid
							.loadData();
				}
			}
			if (typeof(rs) != 'undefined' && rs == true) {
				dialog.close();
			}
		}
	});
	if (typeof(haveDel) == 'undefined' || haveDel == true || haveDel == 'true') {
		btns.push({
			text : '删除',
			onclick : function(item, dialog) {
				jrConfirm("确定删除这条数据吗？", function(v) {
					if (v) {
						var ifm = dialog.frame;
						var tableName = ifm.document
								.getElementById("tableName").value;
						var id = ifm.document.getElementById("zd_id").value;
						var enumNo = ifm.document.getElementById("theform").action;
						if (enumNo.indexOf("enumNo=") != -1) {
							enumNo = enumNo.substring(enumNo.indexOf("enumNo=")
									+ 7);
						}
						jQuery.post("/backend/action/ajax_cud.jsp", {
									flag : 'commonDelete',
									id : id,
									tableName : tableName,
									enumNo : enumNo
								}, function() {
									dialog.close();
									var ifid;
									if (typeof(parent.tab) != 'undefined') {
										ifid = parent.tab
												.getSelectedTabItemID();
										if (typeof(parent.document
												.getElementById(ifid).contentWindow.grid) != 'undefined') {
											parent.document
													.getElementById(ifid).contentWindow.grid
													.loadData();
										}
									}
								});
					}
				});
			}
		});
	}
	btns.push({
				text : '取消',
				onclick : function(item, dialog) {
					dialog.close();
				}
			});
	parent.nowDialog = window.parent.jQuery.ligerDialog.open({
				height : height,
				url : url,
				width : width,
				showMax : false,
				showToggle : false,
				showMin : false,
				isResize : false,
				modal : true,
				title : title,
				buttons : btns
			});
}

/**
 * 遍历所有的iframe得到应该得到的那一个
 * 
 * @param {}
 *            url
 * @return {}
 */
function eachIframe(url) {
	var iframe = null;
	if (url.indexOf('/backend/') != -1) {
		url = url.substring(url.indexOf('/backend/'));
	}
	jQuery.each(jQuery(parent.document).find("iframe"), function(index, data) {
				if (jQuery(this).attr("src") == url) {
					iframe = this;
				}
			})
	return iframe;
}

/**
 * 多表联查
 * 
 * @type String
 */
var main = '';

/**
 * 列表删除方法
 * 
 * @param {}
 *            arg 删除时要传的参数
 */
function toolbarDel(arg) {
	if (typeof(arg) == 'undefined' || arg == null) {
		arg = {};
	}
	var checkedRows = grid.getCheckedRows();
	if (checkedRows.length <= 0) {
		return;
	}
	// 遍历所有的选中行，如果是没有UUID，则移除
	jQuery.each(checkedRows, function(index, data) {
				if (typeof(this.uuid) == 'undefined') {
					jrDeleteRow(this.__index);
				}
			});
	jrConfirm("确定删除选中项吗？", function(v) {
				if (v) {
					var checkedRows = grid.getCheckedRows();
					var idStr = "";
					for (var i = 0; i < checkedRows.length; i++) {
						idStr += "'" + checkedRows[i].uuid + "',";
					}
					if (idStr.indexOf(",") != -1) {
						idStr = idStr.substring(0, idStr.length - 1);
					}
					arg.del_id = idStr;
					if ('undefined' == typeof(arg.tableName)) {
						arg.tableName = tableName;
					}
					executeDel(arg);
				}
			});
}

/**
 * 执行删除的方法
 * 
 * @param {}
 *            data 要传向后台的数据
 */
function executeDel(delData) {
	var enumNo = '';
	for (var i = 0; i < params.length; i++) {
		if (params[i].name == 'enumNo') {
			enumNo = params[i].value;
		}
	}
	jQuery.ajax({
				url : '/backend/action/crud.jsp?enumNo=' + enumNo,
				data : delData,
				type : 'post',
				async : false,
				cache : false,
				success : function(data) {
					grid.loadData();
				}
			});
}

/**
 * 增加和修改的方法
 * 
 * @param {}
 *            obj 行对象
 * @param {}
 *            arg 显示参数 目前拥有 width,height,title,fileName 4个属性
 */
function toolbarAdd(arg, obj) {
	var width = null;
	var height = null;
	var title = null;
	var fileName = null;
	var folderName = null;
	if (typeof(arg) == 'undefined' || typeof(arg.width) == 'undefined') {
		width = 800;
	} else {
		width = arg.width;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.height) == 'undefined') {
		height = 600;
	} else {
		height = arg.height;
	}
	var _url = document.URL;
	if (_url.indexOf("?") != -1) {
		_url = _url.split("?")[0];
	}
	if (_url.indexOf("/backend/") != -1) {
		_url = _url.split("/backend/")[1];
	}
	var _urlArr = _url.split("/");
	var _folder;
	if (_urlArr.length == 3) {
		_folder = _url.split("/")[0] + "/" + _url.split("/")[1];
	} else {
		_folder = _url.split("/")[0];
	}
	var _file = _url.split("/")[1];
	_file = _file.replace("_list.jsp", "");
	if (typeof(arg) == 'undefined' || typeof(arg.title) == 'undefined') {
		title = "编辑";
	} else {
		title = arg.title;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.fileName) == 'undefined') {
		fileName = _file;
	} else {
		fileName = arg.fileName;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.folderName) == 'undefined') {
		folderName = _folder;
	} else {
		folderName = arg.folderName;
	}
	// 增加
	if (typeof(obj) == 'undefined') {
		var url = "/backend/" + folderName + "/" + fileName + "_edit.jsp";
		if ('undefined' != typeof(arg.params) && null != arg.params) {
			url += "?";
			for (var key in arg.params) {
				url += key + "=" + arg.params[key] + "&";
			}
			if (null != url && url.indexOf("&") != -1) {
				url = url.substring(0, url.length - 1);
			}
		}
		jrWindow(url, title, width, height);
	} else {// 修改
		var url = "/backend/" + folderName + "/" + fileName + "_edit.jsp?id="
				+ obj;
		if ('undefined' != typeof(arg.params) && null != arg.params) {
			url += "&";
			for (var key in arg.params) {
				url += key + "=" + arg.params[key] + "&";
			}
			if (null != url && url.indexOf("&") != -1) {
				url = url.substring(0, url.length - 1);
			}
		}
		jrWindow(url, title, width, height);
	}
}

/**
 * 增加和修改的方法
 * 
 * @param {}
 *            obj 行对象
 * @param {}
 *            arg 显示参数 目前拥有 width,height,title,fileName 4个属性
 */
function toolbarAdd(arg, obj, haveDel) {
	var width = null;
	var height = null;
	var title = null;
	var fileName = null;
	var folderName = null;
	if (typeof(arg) == 'undefined' || typeof(arg.width) == 'undefined') {
		width = 800;
	} else {
		width = arg.width;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.height) == 'undefined') {
		height = 600;
	} else {
		height = arg.height;
	}
	var _url = document.URL;
	if (_url.indexOf("?") != -1) {
		_url = _url.split("?")[0];
	}
	if (_url.indexOf("/backend/") != -1) {
		_url = _url.split("/backend/")[1];
	}
	var _urlArr = _url.split("/");
	var _folder;
	if (_urlArr.length == 3) {
		_folder = _url.split("/")[0] + "/" + _url.split("/")[1];
	} else {
		_folder = _url.split("/")[0];
	}
	var _file = _url.split("/")[1];
	_file = _file.replace("_list.jsp", "");
	if (typeof(arg) == 'undefined' || typeof(arg.title) == 'undefined') {
		title = "编辑";
	} else {
		title = arg.title;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.fileName) == 'undefined') {
		fileName = _file;
	} else {
		fileName = arg.fileName;
	}
	if (typeof(arg) == 'undefined' || typeof(arg.folderName) == 'undefined') {
		folderName = _folder;
	} else {
		folderName = arg.folderName;
	}
	// 增加
	if (typeof(obj) == 'undefined') {
		var url = "/backend/" + folderName + "/" + fileName + "_edit.jsp";
		if ('undefined' != typeof(arg.params) && null != arg.params) {
			url += "?";
			for (var key in arg.params) {
				url += key + "=" + arg.params[key] + "&";
			}
			if (null != url && url.indexOf("&") != -1) {
				url = url.substring(0, url.length - 1);
			}
		}
		jrWindow(url, title, width, height, haveDel);
	} else {// 修改
		var url = "/backend/" + folderName + "/" + fileName + "_edit.jsp?id="
				+ obj;
		if ('undefined' != typeof(arg.params) && null != arg.params) {
			url += "&";
			for (var key in arg.params) {
				url += key + "=" + arg.params[key] + "&";
			}
			if (null != url && url.indexOf("&") != -1) {
				url = url.substring(0, url.length - 1);
			}
		}
		jrWindow(url, title, width, height, haveDel);
	}
}

/**
 * 根据键获取枚举值-商品网类别
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var gift_brand_map = null;
function getGiftBrand(key, appName) {
	var value = null;
	if (null == gift_brand_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						'flag' : 'get_name',
						'appName' : appName
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						gift_brand_map = json;
					}
				});
	}
	value = gift_brand_map[key];
	return value;
}

/**
 * 根据键获取枚举值-商品网类别
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var gift_category_map = null;
function getGiftCategory(key, appName) {
	var value = null;
	if (null == gift_category_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						'flag' : 'get_name',
						'appName' : appName
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						gift_category_map = json;
					}
				});
	}
	value = gift_category_map[key];
	return value;
}

/**
 * 根据键获取枚举值-配件网类别
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var part_brand_map = null;
function getPartBrand(key, appName) {
	var value = null;
	if (null == part_brand_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						'flag' : 'get_name',
						'appName' : appName
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						part_brand_map = json;
					}
				});
	}
	value = part_brand_map[key];
	return value;
}

/**
 * 根据键获取枚举值-配件网类别
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var part_category_map = null;
function getPartCategory(key, appName) {
	var value = null;
	if(key != ""){
		if (null == part_category_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
			jQuery.ajax({
				url : '/backend/action/ajax_r.jsp',
				data : {
					'flag' : 'get_name',
					'appName' : appName
				},
				type : 'get',
				async : false,
				cache : true,
				dataType : 'jsonp',
				jsonp : 'callback',
				type : 'post',
				success : function(json) {
					part_category_map = json;
				}
			});
		}
		value = part_category_map[key];
	}
	return value;
}

//根据类别json串，解析最低层类别的编号
function getPartCategoryKey(categoryJsonStr){
	categoryJsonStr = $.trim(categoryJsonStr);
	if(categoryJsonStr=="" || categoryJsonStr==null || categoryJsonStr=="null"){
		return "";
	}
	var key = "";
	var categoryKeyJson = eval(categoryJsonStr);
	if(categoryKeyJson.length > 0){
		key = categoryKeyJson[categoryKeyJson.length-1].c;
	}
	return key;
}

//根据类别号，获取层级类别的json串
function getPartCategoryKeyJson(category_key){
	if(category_key=="" || category_key.length<3){
		return "";
	}
	
	var categoryKeyJsonStr = "";
	for(var i=1; i<=category_key.length/3; i++){
		var c = category_key.substr(0, i*3);
		var n = getPartCategory(c,"partCategoryMap");
		categoryKeyJsonStr += "{'c':'" + c + "','n':'" + n + "'},";
	}
	
	if(categoryKeyJsonStr != ""){
		categoryKeyJsonStr = categoryKeyJsonStr.substring(0, categoryKeyJsonStr.length-1);
		categoryKeyJsonStr = "[" + categoryKeyJsonStr + "]";
	}
	return categoryKeyJsonStr;
}

/**
 * 根据键获取枚举值
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var enum_map = null;
function getEnum(key) {
	var value = null;
	if (null == enum_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						'flag' : 'get_enum'
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						enum_map = json;
					}
				});
	}
	value = enum_map[key];
	return value;
}

/**
 * 根据键获取枚举值
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var brand_map = null;
function getBrand(key, enumNo) {
	var value = null;
	if (null == brand_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						flag : 'get_brand',
						enumNo : enumNo
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						brand_map = json;
					}
				});
	}
	value = brand_map[key];
	if (typeof(value) == 'undefined') {
		return '';
	}
	return value;
}

/**
 * 根据键获取枚举值
 * 
 * @param {}
 *            key 键
 * @return {}
 */
var category_map = null;
function getCategory(key, enumNo) {
	var value = null;
	if (null == category_map) {// 如果枚举时空，则从服务器取回，否则，直接拿本地的
		jQuery.ajax({
					url : '/backend/action/ajax_r.jsp',
					data : {
						flag : 'get_category',
						enumNo : enumNo
					},
					type : 'get',
					async : false,
					cache : true,
					dataType : 'jsonp',
					jsonp : 'callback',
					type : 'post',
					success : function(json) {
						category_map = json;
					}
				});
	}
	value = category_map[key];
	if (typeof(value) == 'undefined') {
		return '';
	}
	return value;
}

/**
 * 通用同级排序
 */
function commonSort(arg) {
	var url = "/backend/function/sort.jsp?tableName=" + arg.tableName;
	url += "&value=" + arg.value;
	url += "&enumNo=" + arg.enumNo;
	jrWindow(url, "排序", 300, 300);
}

/**
 * 选择文件
 * 
 * @param {}
 *            id
 */
function chooseFile(id, w, h) {
	var url = "/backend/function/file/choose_list.jsp?id=" + id;
	var title = "选择";
	var width = 650;
	if (typeof(w) != 'undefined') {
		width = w;
	}
	var height = 400;
	if (typeof(h) != 'undefined') {
		height = h;
	}
	jQuery.ligerDialog.open({
				height : height,
				url : url,
				width : width,
				showMax : true,
				showToggle : false,
				showMin : false,
				isResize : false,
				modal : true,
				title : title,
				buttons : [{
					text : '确定',
					onclick : function(item, dialog) {
						dialog.frame.doSub(dialog);
						var ifid = parent.tab.getSelectedTabItemID();
						parent.document.getElementById(ifid).contentWindow.grid
								.loadData();
					}
				}, {
					text : '取消',
					onclick : function(item, dialog) {
						dialog.close();
					}
				}]
			});
}

/**
 * 执行ajax的方法
 * 
 * @param {}
 *            url 请求地址
 * @param {}
 *            data post数据
 * @param {}
 *            fun 回调函数
 * @param {}
 *            async 是否异步
 */
function doAjax(url, data, fun, async) {
	if ('undefined' == typeof(async)) {
		async = true;
	}
	jQuery.ajax({
				url : url,
				type : 'post',
				data : data,
				async : async,
				cache : false,
				success : function(data) {
					if ('undefined' != typeof(fun)) {
						fun(data);
					}
				}
			});
}

function doClearForm() {
	jQuery(".searchForm input:text,select").val('');
}

jQuery(".searchForm input[type=text]").keypress(function(e) {
			if (e.keyCode == 13) {
				doSearch();
			}
		});

// 增加和编辑的方法
function addAndEdit(index) {
	var w = 800;
	var h = 500;
	if (typeof(windowWidth) != 'undefined') {
		w = windowWidth;
	}
	if (typeof(windowHeight) != 'undefined') {
		h = windowHeight;
	}
	if ('undefined' == typeof(index)) {// 如果是增加
		toolbarAdd({
					width : w,
					height : h,
					title : '增加',
					params : {
						channel_uuid : channelUUID
					}
				});
	} else {// 如果是修改
		if (typeof jQuery(grid.getRowObj(index))
				.find("a[onclick^='addAndEdit']") != 'undefined') {
			jQuery(grid.getRowObj(index)).find("a[onclick^='addAndEdit']")
					.html("<font color='red'>"
							+ jQuery(grid.getRowObj(index))
									.find("a[onclick^='addAndEdit']").html()
							+ "</font>");
		}
		var row = grid.getRow(index);
		toolbarAdd({
					width : w,
					height : h,
					title : '修改'
				}, row.uuid);
	}
}

// 增加和编辑的方法
function addAndEdit(index, haveDel) {
	var w = 800;
	var h = 500;
	if (typeof(windowWidth) != 'undefined') {
		w = windowWidth;
	}
	if (typeof(windowHeight) != 'undefined') {
		h = windowHeight;
	}
	if ('undefined' == typeof(index)) {// 如果是增加
		toolbarAdd({
					width : w,
					height : h,
					title : '增加',
					params : {
						channel_uuid : channelUUID
					}
				}, undefined, haveDel);
	} else {// 如果是修改
		if (typeof jQuery(grid.getRowObj(index))
				.find("a[onclick^='addAndEdit']") != 'undefined') {
			jQuery(grid.getRowObj(index)).find("a[onclick^='addAndEdit']")
					.html("<font color='red'>"
							+ jQuery(grid.getRowObj(index))
									.find("a[onclick^='addAndEdit']").html()
							+ "</font>");
		}
		var row = grid.getRow(index);
		toolbarAdd({
					width : w,
					height : h,
					title : '修改'
				}, row.uuid, haveDel);
	}
}

function Dev21sunGrid(config) {
	if (url == '') {
		url = "/backend/action/liger.jsp";
	}
	params.push({
				'name' : 'tableName',
				'value' : tableName
			});
	params.push({
				'name' : 'fields',
				'value' : fields
			});
	params.push({
				'name' : 'whereStr',
				'value' : whereStr
			});
	params.push({
				'name' : 'orderBy',
				'value' : orderBy
			});
	var buttons = null;
	// 如果查询不是关闭状态
	if (typeof(config) != 'undefined'
			&& typeof(config.searchIsClose) != 'undefined'
			&& !config.searchIsClose) {
		buttons = [{
					text : '增加',
					click : function() {
						addAndEdit();
					},
					icon : 'add'
				}, {
					text : '删除',
					click : function() {
						toolbarDel({
									channel_uuid : channelUUID
								});
					},
					icon : 'delete'
				}, {
					text : '关闭查询',
					click : function() {
						closeAndOpen();
					},
					icon : 'busy'
				}];
		jQuery(".searchForm").show();
	} else {
		buttons = [{
					text : '增加',
					click : function() {
						addAndEdit();
					},
					icon : 'add'
				}, {
					text : '删除',
					click : function() {
						toolbarDel({
									channel_uuid : channelUUID
								});
					},
					icon : 'delete'
				}, {
					text : '打开查询',
					click : function() {
						closeAndOpen();
					},
					icon : 'right'
				}];
	}
	var myToolbar = {
		items : buttons
	};
	if (typeof(config) != 'undefined' && typeof(config.toolbar) != 'undefined') {
		myToolbar = config.toolbar;
	}
	// 增加的按钮
	if (typeof(config) != 'undefined'
			&& typeof(config.addToolbar) != 'undefined') {
		for (var i = 0; i < config.addToolbar.length; i++) {
			myToolbar.items.push(config.addToolbar[i]);
		}
	}

	var defualts = {
		url : url,
		toolbar : myToolbar,
		columns : columnsArr,
		id : "maingrid",
		alternatingRow : true,
		addColumns : true, // 是否追加列
		params : params,
		data : null,
		width : "99.8%",
		height : "98%",
		pageSize : 20,
		showTitle : false,
		checkbox : true,
		RequireData : false,
		tableName : null,
		tree : null,
		async : true,
		usePager : true,
		onSuccess : function() {

		},
		onLoaded : null,
		title : null,
		enabledEdit : false,
		selectRowButtonOnly : true,
		rownumbers : true,
		clickToEdit : false,
		isChecked : function(obj) {
		},
		onAfterEdit : null,
		onBeforeSubmitEdit : function(obj) {

		},
		onDblClickRow : function(data, rowindex, rowobj) {

		},
		tree : null
	};
	var opts = jQuery.extend(true, {}, defualts, config);
	var g = jQuery("#" + opts.id).ligerGrid({
				columns : opts.columns,
				url : opts.url,
				pageSize : opts.pageSize,
				method : "post",
				tree : opts.tree,
				width : opts.width,
				height : opts.height,
				checkbox : opts.checkbox,
				selectRowButtonOnly : opts.selectRowButtonOnly,
				parms : opts.params,
				onLoaded : opts.onLoaded,
				usePager : opts.usePager,
				showTitle : opts.showTitle,
				alternatingRow : opts.alternatingRow,
				rownumbers : opts.rownumbers,
				toolbar : opts.toolbar,
				clickToEdit : opts.clickToEdit,
				enabledEdit : opts.enabledEdit,
				isChecked : opts.isChecked,
				frozenCheckbox : true,
				tree : opts.tree,
				rownumbers : true,
				allowUnSelectRow : true,
				async : opts.async,
				frozenRownumbers : false,
				title : opts.title,
				onSuccess : opts.onSuccess,
				onAfterShowData : opts.onAfterShowData,
				data : opts.data,
				RequireData : opts.RequireData,
				onDblClickRow : opts.onDblClickRow,
				onBeforeSubmitEdit : opts.onBeforeSubmitEdit,
				onAfterEdit : opts.onAfterEdit
			});
	jQuery("#pageloading").hide();
	return g;
}

jQuery.ligerDefaults.Grid.formatters['date'] = function(content, column) {
	return ((content == null || typeof(content) == 'undefined') ? '' : content
			.substring(0, content.indexOf(' ')));
}
jQuery.ligerDefaults.Grid.formatters['is'] = function(content, column) {
	if (content == 1) {
		return "<font color='green'>是</font>";
	}
	return "<font color='red'>否</font>";
}
jQuery.ligerDefaults.Grid.formatters['sex'] = function(content, column) {
	if (content == 1) {
		return '男';
	}
	return '女';
}
/**
 * 查看会员
 */
function viewMember(mem_no) {
	var _url = "/backend/member.21-sun.com/member/member_info.jsp?mem_no="
			+ mem_no;
	var _title = "会员" + mem_no;
	var iWidth = 800;
	var iHeight = 600;
	var iTop = (window.screen.height - 30 - iHeight) / 2;
	var iLeft = (window.screen.width - 10 - iWidth) / 2;
	var _par = "height="
			+ iHeight
			+ ",width="
			+ iWidth
			+ ",top="
			+ iTop
			+ ",left="
			+ iLeft
			+ ",toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no";
	// window.open(_url, _title, _par);
	jrWindow(_url, _title, iWidth, iHeight);
}

jQuery.ligerDefaults.Grid.formatters['link'] = function(content, column) {
	return '<a class="link" href="' + content + '" target="_blank">' + content
			+ '</a>';
}

function checkBoxTree(opts) {
	var defualts = {
		height : 200,
		width : 350,
		top : 0,
		left : 0
	};
	opts = jQuery.extend(true, {}, defualts, opts);
	var _obj = jQuery("#template_channel_" + opts.id);
	if (_obj.length > 0) {
		_obj.show();
	} else {
		var htm = '<div style="display: none;width: ' + opts.width
				+ 'px;height: ' + opts.height
				+ 'px;border:none;position: relative;top: ' + opts.top
				+ 'px;left: ' + opts.left
				+ 'px;background: none;z-index: 99999;" id="template_channel_'
				+ opts.id + '">';
		htm += '<ul style="float:left;width:'
				+ (opts.width - 55)
				+ 'px; height:'
				+ (opts.height - 1)
				+ 'px;overflow-x: hidden; overflow-y: scroll;border:1px solid #ccc;background:#fff;" id="tree_'
				+ opts.id + '" style="margin-top: 3px;" class="ztree"></ul>';
		htm += '<div style="float:left; width:30px; height:18px;background:#fff;border:1px solid #ccc;cursor:pointer;" onclick="jQuery(\'#template_channel_'
				+ opts.id + '\').hide();">关闭</div>';
		htm += '<div style="clear:left;"></div>';
		htm += '</div>';

		jQuery("#" + opts.id).after(htm);
		var setting = {
			view : {
				dblClickExpand : false,
				showLine : true,
				selectedMulti : false,
				expandSpeed : (jQuery.browser.msie && parseInt($.browser.version) <= 6)
						? ""
						: "fast"
			},
			data : {
				simpleData : {
					enable : true,
					idKey : "id",
					pIdKey : "pId",
					rootPId : "template"
				}
			}
		};
		jQuery.fn.zTree.init(jQuery("#tree_" + opts.id), setting,
				opts.zTreeNodes);
		jQuery("#" + opts.id).click(function() {
					jQuery("#template_channel_" + opts.id).show();
				});
	}
}

/**
 * 对表单添加效果
 */
jQuery(function() {
			var jrCss = jQuery(".jr_text,jr_select");
			jrCss.focus(function() {
						jQuery(this).css("border", "1px solid #000");
					});
			jrCss.blur(function() {
						jQuery(this).css("border", "1px solid #999");
					});
			jQuery(".jr_text[readonly=readonly]").css("color", "#666");
		})

// ----------需要全屏显示，做一下处理
var obj;
function closeAndOpen() {
	if (jQuery(".l-icon-busy").parent().find("span").html() == '关闭查询') {
		var tag = jQuery(".l-icon-busy");
		with (tag) {
			parent().find("span").html("打开查询");
			removeClass("l-icon-busy").addClass("l-icon-right");
			jQuery(".searchForm").hide();
			grid.loadData();
		}
	} else {
		var tag = jQuery(".l-icon-right");
		with (tag) {
			removeClass("l-icon-right").addClass("l-icon-busy");
			parent().find("span").html("关闭查询");
			jQuery(".searchForm").show();
			grid.loadData();
		}
		jQuery(obj).insertBefore(jQuery("body div:eq(0)"));
	}
}
